import {useSettingStore} from "@/stores/modules/setting"
import {defaultSettings} from "@/config/setting"
import debounce from "lodash/throttle"

const toggleMobile = (bool: boolean) => {
    document.documentElement.classList.toggle('is-mobile', bool)
}

export const publicFun = () => {
    const settings = useSettingStore()
    window.addEventListener(
        "resize",
        debounce(() => {
            const width = document.documentElement.clientWidth

            if (width < 768) {
                settings.flag = true
            } else {
                settings.flag = false
            }

            toggleMobile(settings.flag)
        }, 500),
    )
    const width = document.documentElement.clientWidth
    if (width < 768) {
        defaultSettings.isShowMenu = false
        settings.flag = true
    } else {
        defaultSettings.isShowMenu = true
        settings.flag = false
    }
    toggleMobile(settings.flag)
}
